package com.avcdata.aoscustommade.main;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.WindowManager;

import com.tandong.swichlayout.SwichLayoutInterFace;
import com.tandong.swichlayout.SwitchLayout;

/**
 *Activity基类
 */
public abstract class BaseActivity extends FragmentActivity implements View.OnClickListener, SwichLayoutInterFace {
    public Bundle savedInstanceState;
    private ProgressDialog progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.savedInstanceState = savedInstanceState;
        super.onCreate ( savedInstanceState );
        setEnterSwichLayout ();
        initView ();
        initInstall();
        initData();
        evenControl();

    }

    @Override
    public void setEnterSwichLayout() {

    }

    @Override
    public void setExitSwichLayout() {
        SwitchLayout.getSlideToLeft ( this, true, null );
    }

    @Override
    protected void onDestroy() {
        super.onDestroy ();
//        AppActivityManager.getAppManager().finishAllActivity();
    }

    @Override
    public void onClick(View view) {
        onClickEvent ( view );
    }



    /**
     * 初始化布局
     */
    abstract public void initView();

    /***
     * 初始化设置
     */
    abstract public void initInstall();


    /***
     * 初始化数据
     */
    abstract public void initData();


    /***
     * 事件控制
     */
    abstract public void evenControl();

    /**
     * onClick方法的封装，在此方法中处理点击事件
     * @param view 被点击的View对象
     */
    abstract public void onClickEvent(View view);




    /**
     * 显示正在加载的进度条(不含内容)
     */
    public void showProgressDialog() {
        if (progressDialog != null && progressDialog.isShowing ()) {
            progressDialog.dismiss ();
            progressDialog = null;
        }
        progressDialog = new ProgressDialog ( BaseActivity.this );
        progressDialog.setCanceledOnTouchOutside ( false );
        try {
            progressDialog.show ();
        } catch (WindowManager.BadTokenException exception) {
            exception.printStackTrace ();
        }
    }

    /***
     * 显示正在加载的进度条
     *
     * @param msg 显示的内容
     */
    public void showProgressDialog(String msg) {
        if (progressDialog != null && progressDialog.isShowing ()) {
            progressDialog.dismiss ();
            progressDialog = null;
        }
        progressDialog = new ProgressDialog ( BaseActivity.this );
        progressDialog.setMessage ( msg );
        try {
            progressDialog.show ();
        } catch (WindowManager.BadTokenException exception) {
            exception.printStackTrace ();
        }
    }

    /**
     * 隐藏正在加载的进度条
     */
    public void dismissProgressDialog() {
        if (null != progressDialog && progressDialog.isShowing () == true) {
            progressDialog.dismiss ();
            progressDialog = null;
        }
    }

}
